package com.example.receiver;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class VoiceShow extends Activity{
	
	TextView txturlvoice;
	String urlvoice;
	Button download;
	Button accept;
	double getdatalat;
	double getdatalng;
	double emerlat;
	double emerlng;
	private LocationManager lm;
	GoogleMap myMap;
	public double latchange = 0;
	public double lngchange = 0;
	LatLng curpoint;
	LatLng despoint;
	public Context con;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.showvoice);
		
		txturlvoice = (TextView) findViewById(R.id.txtvoice);
		download = (Button) findViewById(R.id.btndownload);
		accept = (Button) findViewById(R.id.btnacceptvoice);
		
		urlvoice = getIntent().getStringExtra("voiceurl");
		txturlvoice.setText("URL of this voice : "+urlvoice);
		
		getdatalat = getIntent().getDoubleExtra("emerlat", emerlat);
		getdatalng = getIntent().getDoubleExtra("emerlng", emerlng);
		despoint = new LatLng(getdatalat, getdatalng);
		Log.d("getdatalat", "" + getdatalat);
		Log.d("des", "" + despoint);

		lm = (LocationManager) getSystemService(LOCATION_SERVICE);
		con = new VoiceShow();
		GetCurLocation curlocation = new GetCurLocation(lm, this, myMap);
		latchange = curlocation.getMlat();
		Log.d("latchange", "" + latchange);
		lngchange = curlocation.getMlng();
		curpoint = new LatLng(latchange, lngchange);
		Log.d("curpoint", "" + curpoint);
		
		
		download.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				Intent gotonext = new Intent(VoiceShow.this,DownloadFile.class);
				gotonext.putExtra("urlvoice",urlvoice);
				startActivity(gotonext);
					
			}
		});
		
		
		accept.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				BlackgroupService.isLooping = true;
				HttpPostUpdate post = new HttpPostUpdate();
				post.curpoint(getdatalat, getdatalng);
				post.posts
						.execute("http://172.16.149.122/myexample/update.php");

			}
		});
		
		
	}
	
	

}
